package com.wuxiaofan.service;

import com.alibaba.fastjson.JSONObject;
import com.wuxiaofan.entity.ProductInfo;
import com.wuxiaofan.mapper.ProductInfoMapper;
import com.wuxiaofan.util.DateUtils;
import com.wuxiaofan.util.KeyWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class ProductInfoService {


    @Autowired
    private ProductInfoMapper productInfoMapper;

    public ProductInfo findById(String id){
        return productInfoMapper.selectById(id);
    }

    public void updateByMap(Map paraMap){
        productInfoMapper.updateMapById(paraMap);
    }

    public ProductInfo insert(ProductInfo productInfo){
        productInfo.setId(KeyWorker.nextIdStr());
        productInfo.setCreateTime(DateUtils.getNowDate());
        productInfoMapper.insert(productInfo);
        return productInfo;
    }

    public void subRepertory(String id,int num){
        Map paraMap = new HashMap();
        paraMap.put("id",id);
        paraMap.put("subRepertory",num+"");
        updateByMap(paraMap);
    }
}
